package com.example.NeteaseCloudMusicApi.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.NeteaseCloudMusicApi.R;
import com.example.NeteaseCloudMusicApi.entity.ListSong;
import java.util.List;

public class ListSongAdapter extends RecyclerView.Adapter<ListSongAdapter.ViewHolder> {

    private List<ListSong> mListSong;


    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView songName;
        TextView singer;
        TextView num;
        TextView album;
        public ViewHolder (View view) {
            super(view);
            num =view.findViewById(R.id.num);
            songName = view.findViewById(R.id.song_name);
            singer = view.findViewById(R.id.singer);
            album = view.findViewById(R.id.album);
        }
    }

    public ListSongAdapter(List<ListSong> listSongs){
        mListSong = listSongs;
        }
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.song_item_list,parent,false);
            ViewHolder holder = new ViewHolder(view);
            return holder;
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position){

            ListSong listSong = mListSong.get(position);
            holder.num.setText(listSong.getNum());
            holder.songName.setText(listSong.getSongName());
            holder.singer.setText(listSong.getSinger());
            holder.album.setText(listSong.getAlbum());

        }

        @Override
        public int getItemCount(){
            return mListSong.size();
        }
}
